package com.example.demo.service.impl;

import com.example.demo.entity.Scores;
import com.example.demo.entity.User;
import com.example.demo.mapper.DmMapper;
import com.example.demo.service.DmService;
import com.example.demo.vo.UserVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class DmServiceImpl implements DmService{

    @Autowired
    private DmMapper dmMapper;

    @Override
    public List<User> selectUser() {
        return dmMapper.selectUser();
    }

    @Override
    public void insert() {
        dmMapper.insert();
    }

    @Override
    public List<UserVo> selectUserScore() {
        List<UserVo> userScores=new ArrayList<>();
        List<Scores> scores = dmMapper.selectUserScore();
        scores.stream().forEach(e ->{
            UserVo userVo=new UserVo();
            userVo.setName(e.getUserName());
            userVo.setScores(e.getScores());
            userVo.setSubjectName(e.getSubjectName());
            userScores.add(userVo);
        });
        return userScores;
    }
}
